<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Multi Wasm Example</title>
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  <meta name="apple-touch-fullscreen" content="yes" />
  <meta name="format-detection" content="telephone=no, email=no" />
</head>

<body>
  <h1>Multi Wasm Example</h1>
  <div>See result in the console</div>

  <script>
    function loadModules (modules) {
      return Promise.all(modules.map(
        path => fetch(path)
          .then(response => response.arrayBuffer())
          .then(WebAssembly.instantiate)
          .then(mod => mod.instance)
      ))
    }

    loadModules(['inc.wasm', 'square.wasm'])
      .then(([A, B]) => {
        const inc = A.exports.inc
        const square = B.exports.square

        console.log('2 + 1 =', inc(2))
        console.log('3 + 1 =', inc(3))

        console.log('2^2 =', square(2))
        console.log('3^2 =', square(3))

        console.log('(7 + 1)^2 =', square(inc(7)))
      })
  </script>
</body>
</html>
